import axios from 'axios';
import env from '../config/env';

let util = {

};
util.title = function (title) {
    title = title ? title + ' - Home' : 'Rloud Room';
    window.document.title = title;
};

const ajaxUrl = env === 'development' ?
    'http://127.0.0.1:8888' :
    env === 'production' ?
        'https://www.url.com' :
        'https://debug.url.com';

util.ajax = axios.create({
    baseURL: ajaxUrl,
    timeout: 30000
});


function random(size) {
    let seed = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'Q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
    );//数组
    let seedlength = seed.length;//数组长度
    let create = '';
    let j = '';
    for (let i = 0; i < size; i++) {
        j = Math.floor(Math.random() * seedlength);
        create += seed[j];
    }
    return create;
}

function string(size) {
    size = size || 16;
    return random(size);
}

util.randomString = string;

export default util;